package com.dtu.distributed.filereader;

import java.io.BufferedReader;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;

public class ReadNodeList {

	public HashMap<Integer, String> retrieveNodes(String path){
		HashMap<Integer, String> result=new HashMap<Integer,String>();
		DataInputStream dataIn=null;
		try{
			  
			  FileInputStream fileStream = new FileInputStream(path);
			 
			  dataIn = new DataInputStream(fileStream);
			  BufferedReader buffReader = new BufferedReader(new InputStreamReader(dataIn));
			  String nodeLine;

			while ((nodeLine = buffReader.readLine()) != null) {
				if(!nodeLine.equals("") && !nodeLine.equals(" ")){
				String line=nodeLine.trim();
				String[] nodeArray = line.split(":");
				int id = Integer.parseInt(nodeArray[0].trim());
				String value = nodeArray[1] + ":" + nodeArray[2];
				result.put(id, value);
				}
			}
			  dataIn.close();
		  }
		  catch (Exception e){//Catch exception if any
			 
		     System.err.println("Error1: " + e.getMessage());
		  }
		
		
		return result;
	}

}
